<?php
use yii\widgets\ActiveForm;
use yii\helpers\Html;
//use kartik\datetime\DateTimePickerAsset;
//DateTimePickerAsset::register($this);
?>
<?php $form = ActiveForm::begin(['enableAjaxValidation' => false,'enableClientValidation' => true,'options'=>['class'=>'form-validate']]); ?>
<table width="100%" class="table-form"  data-condition="<?=$model->conditions?>">
    <tr>
        <th width="80" align="right"><?= $model->attributeLabels()['name']; ?></th>
        <td><?= $form->field($model, 'name', ['template' => '{input}{error}{hint}'])->textInput(['style' => 'width:180px','class' => 'input-text']) ?></td>
    </tr>
    <tr>
        <th width="80" align="right"><?= $model->attributeLabels()['code']; ?></th>
        <td><?= $form->field($model, 'code', ['template' => '{input}{error}{hint}'])->textInput(['style' => 'width:180px','class' => 'input-text']) ?></td>
    </tr>
    <tr>
        <th width="80" align="right"><?= $model->attributeLabels()['type']; ?></th>
        <td><?= $form->field($model, 'type', ['template' => '{input}{error}{hint}'])->dropDownList(['full'=>'满减券','freight'=>'运费券'],['prompt'=>'选择券类型','style' => 'width:180px','class' => 'input-dropdownlist']) ?></td>
    </tr>
    <tr>
        <th width="80" align="right"><?= $model->attributeLabels()['description']; ?></th>
        <td><?= $form->field($model, 'description', ['template' => '{input}{error}{hint}'])->widget(\doumiaoduo\ueditor\Ueditor::className(), ['clientOptions'=>[
                'serverUrl'=>\common\components\helpers\Fun::url(['/uploader/action']),
                'toolbars'=>[['fullscreen', 'source', '|', 'undo', 'redo', '|','bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript','rowspacingtop', 'rowspacingbottom', 'lineheight', '|','justifyleft', 'justifycenter', 'justifyright', 'justifyjustify','simpleupload']],
                'initialFrameWidth'=>'100%'
            ]]); ?></td>
    </tr>
    <tr>
        <th width="80" align="right"><?= $model->attributeLabels()['amount']; ?></th>
        <td><?= $form->field($model, 'amount', ['template' => '{input}{error}{hint}'])->textInput(['style' => 'width:180px', 'class' => 'input-text']) ?></td>
    </tr>
    <tr>
        <th width="80" align="right"><?= $model->attributeLabels()['total']; ?></th>
        <td><?= $form->field($model, 'total', ['template' => '{input}{error}{hint}'])->textInput(['style' => 'width:180px', 'class' => 'input-text']); ?></td>
    </tr>
    <tr>
        <th width="80" align="right"><?= $model->attributeLabels()['quantity']; ?></th>
        <td><?= $form->field($model, 'quantity', ['template' => '{input}{error}{hint}'])->textInput(['style' => 'width:180px', 'class' => 'input-text']); ?></td>
    </tr>
    <tr>
        <th width="80" align="right"><?= $model->attributeLabels()['start_time']; ?></th>
        <td><?= $form->field($model, 'start_time', ['template' => '{input}{error}{hint}'])->textInput([ 'class' => 'form_datetime input-text']); ?></td>
    </tr>
    <tr>
        <th width="80" align="right"><?= $model->attributeLabels()['end_time']; ?></th>
        <td><?= $form->field($model, 'end_time', ['template' => '{input}{error}{hint}'])->textInput([ 'class' => 'form_datetime input-text']); ?></td>
    </tr>
    <tr>
        <th width="80" align="right"><?= $model->attributeLabels()['platforms']; ?></th>
        <td><?= $form->field($model, 'platforms', ['template' => '{input}{error}{hint}'])->checkboxList(['pc'=>'pc端','wechat'=>'微信端','app'=>'app端'],['style' => 'width:180px', 'class' => 'input-checkboxlist']); ?></td>
    </tr>
    <tr>
        <th width="80" align="right"><?= $model->attributeLabels()['conditions']; ?></th>
        <td><?= $form->field($model, 'conditions', ['template' => '{input}{error}{hint}'])->radioList(['all'=>'指定所有商品','type'=>'指定商品类型','cate'=>'指定商品分类','brand'=>'指定商品品牌'],['style' => 'width:180px', 'class' => 'input-radiolist']); ?></td>
    </tr>
    <tr class='condition' id ='type' style="display:none">
        <th width="80" align="right">选择类型</th>
        <td><?=Html::checkboxList('array[type]',isset($checked_values)?$checked_values:null,$type_array,['class' => 'input-checkboxlist'])?></td>
    </tr>
    <tr  class='condition' id="cate" style="display:none">
        <th width="80" align="right">选择分类</th>
        <td><?=Html::checkboxList('array[cate]',isset($checked_values)?$checked_values:null,$tree,['class' => 'input-dropdownlist'])?></td>
    </tr>
    <tr  class='condition' id="brand" style="display:none">
        <th width="80" align="right">选择品牌</th>
        <td><?=Html::checkboxList('array[brand]',isset($checked_values)?$checked_values:null,$brand_array,['class' => 'input-checkboxlist'])?></td>
    </tr>
</table>
    <div class="m_top_10 btn">
        <?= \yii\helpers\Html::submitButton('提交', ['class' => "button", 'id' => 'dosubmit']) ?>
    </div>
<?php \yii\widgets\ActiveForm::end(); ?>
<?php
$js = <<<JS
    var conditions=null;
    var ids='';

    var id=$('.table-form').data('condition');
    if(id!=''){
       $('#'+id).show();
    }
       $(".form_datetime").datetimepicker({
        autoclose: true,
        minuteStep:1,
        todayHighlight:true
    });
    conditions=$('#coupons-conditions input[type=radio]:checked').val();
    $('#coupons-conditions input[type=radio]').change(function(){
        var val=$(this).val();
        conditions=val;
        $('.condition').hide();
        $('#'+val).show();
    });

    $('#dosubmit').click(function(){
        if(conditions!='all'){
             $('#'+conditions+ " input:checked").each(function() {
                (ids =='') ? ids = $(this).val() : ids += ',' + $(this).val();
             });
             if(ids.length==0){
                alert('请根据使用条件进行相关设置！');return false;
             }
        }

    })
JS;
$this->registerJS($js);
?>

